export const formatBytes = (bytes, decimals = 2) => {
    if (bytes === 0) return '0 B'
    const k = 1024
    const dm = decimals < 0 ? 0 : decimals
    const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
    const i = Math.floor(Math.log(bytes) / Math.log(k))
    return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
}

// 获取文件类型
export const getFileType = suffix => {
    let result = ''
    // 图片格式
    const imglist = ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'svg']
    // 进行图片匹配
    result = imglist.find(item => item === suffix)
    if (result) {
        return 'image'
    }
    // 图片格式
    const tiflist = ['tiff', 'tif']
    // 进行图片匹配
    result = tiflist.find(item => item === suffix)
    if (result) {
        return 'tif'
    }
    // 匹配txt
    const txtlist = ['txt']
    result = txtlist.find(item => item === suffix)
    if (result) {
        return 'txt'
    }
    // 匹配 excel
    const excelist = ['xls', 'xlsx']
    result = excelist.find(item => item === suffix)
    if (result) {
        return 'excel'
    }
    // 匹配 word
    const wordlist = ['doc', 'docx']
    result = wordlist.find(item => item === suffix)
    if (result) {
        return 'word'
    }
    // 匹配 pdf
    const pdflist = ['pdf']
    result = pdflist.find(item => item === suffix)
    if (result) {
        return 'pdf'
    }
    // 匹配 ppt
    const pptlist = ['ppt', 'pptx']
    result = pptlist.find(item => item === suffix)
    if (result) {
        return 'ppt'
    }
    // 匹配 视频
    const videolist = ['mp4', 'm2v', 'mkv', 'rmvb', 'avi', 'flv', 'mov', 'm4v']
    result = videolist.find(item => item === suffix)
    if (result) {
        return 'video'
    }
    // 匹配 音频
    const radiolist = ['mp3', 'wav']
    result = radiolist.find(item => item === suffix)
    if (result) {
        return 'audio'
    }
    // 匹配 压缩
    const ziplist = ['zip', 'rar', 'jar', 'tar', 'gzip']
    result = ziplist.find(item => item === suffix)
    if (result) {
        return 'zip'
    }
    // 匹配 ofd
    const ofdlist = ['ofd']
    result = ofdlist.find(item => item === suffix)
    if (result) {
        return 'ofd'
    }
    // 匹配 rtf
    const rtflist = ['rtf']
    result = rtflist.find(item => item === suffix)
    if (result) {
        return 'rtf'
    }
    // 其他 文件类型
    return 'other'
}
